/**
 * Author xiaol
 * Rev
 * Date: 2021-03-29 22:34
 * <p>
 * Copyright (C) 2021 Seeyon, Inc. All rights reserved.
 * <p>
 * This software is the proprietary information of Seeyon, Inc.
 * Use is subject to license terms.
 * @company seeyon.com
 * @author xiaol
 */
package com.lagou.datasource;

import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @description
 * @date 2021-03-29 22:34
 * @author xiaol
 */
public class DataSourceConfig {
	private static ThreadLocal<Connection> threadLocal = new ThreadLocal();

	public static void setConnection(Connection conn){
		threadLocal.set(conn);
	}

	public static Connection getConnection() throws SQLException {
		if(threadLocal.get() != null){
			return threadLocal.get();
		}
		JdbcTemplate jdbcTemplate = new JdbcTemplate();
		return jdbcTemplate.getDataSource().getConnection();
	}
}
